package fc;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;


public class GetToken {

//第一步做一次就行了  记录下来
    /**
     * 模拟缓存服务
     */
    private static final Map<String,String> SYSTEM_CACHE = new HashMap<>();

    /**
     * ecology 系统发放的授权许可证(appid)
     */


    public static Map<String,Object> testGetoken(){

        String secret =FcHttpCon.SECRET;
        String spk = FcHttpCon.SPK;
        String APPID = FcHttpCon.APPID;

        RSA rsa = new RSA(null,spk);
        //对秘钥进行加密传输，防止篡改数据
        String encryptSecret = rsa.encryptBase64(secret,CharsetUtil.CHARSET_UTF_8,KeyType.PublicKey);
        //调用 ECOLOGY 系统接口进行注册
        String data = HttpRequest.post("http://oa.maxwell-gp.com:8090/api/ec/dev/auth/applytoken")
                .header("appid",APPID)
                .header("secret",encryptSecret)
                .header("time","3600")
                .execute().body();
        Map<String,Object> datas = JSONUtil.parseObj(data);
        return datas;
    }


}
